<?php


namespace App\backend\controllers\goods;


use App\backend\controllers\AdminBaseController;
use App\backend\models\GoodSupportModel;
use App\backend\services\GoodSupportServices;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Validator;

class GoodSupportController extends AdminBaseController
{
    protected $class_name = 'GoodSupport';

    /**
     * 商品支持列表
     */
    public function getList(Request $request)
    {
        $data = $request->all();
        $validator = Validator::make(
            $data,
            GoodSupportModel::rules(),
            GoodSupportModel::message()
        );
        if ($validator->fails()) {
            $msg = $validator->errors()->all();
            return errorJson($msg[0], []);
        }
        $list = GoodSupportServices::getList($data);
        return successJson('获取成功!', $list);
    }

    /**
     * 添加/编辑商品支持
     */
    public function goodSupportModify(Request $request)
    {
        $data = $request->all();
        $validator = Validator::make(
            $data,
            GoodSupportModel::modify_rules(),
            GoodSupportModel::message()
        );
        if ($validator->fails()) {
            $msg = $validator->errors()->all();
            return errorJson($msg[0], []);
        }
        $list = GoodSupportServices::goodsGroupModify($data);
        if (!$list) {
            return errorJson('操作失败！', []);
        }
        return successJson('操作成功！', $list);
    }

    /**
     * 删除商品支持
     */
    public function goodSupportDelete(Request $request)
    {
        $data = $request->all();
        $validator = Validator::make(
            $data,
            GoodSupportModel::updated_rules(),
            GoodSupportModel::message()
        );
        if ($validator->fails()) {
            $msg = $validator->errors()->all();
            return errorJson($msg[0], []);
        }
        $list = GoodSupportServices::updateGoodsGroupStatus($data);
        if (!$list) {
            return errorJson('操作失败！', []);
        }
        return successJson('操作成功！', []);
    }

    /**
     * 商品支持详情
     */
    public function goodSupportInfo(Request $request)
    {
        $data = $request->all();
        $validator = Validator::make(
            $data,
            GoodSupportModel::info_rules(),
            GoodSupportModel::message()
        );
        if ($validator->fails()) {
            $msg = $validator->errors()->all();
            return errorJson($msg[0], []);
        }
        $list = GoodSupportServices::goodSupportInfo($data);
        return successJson('操作成功！', $list);
    }

}
